﻿Imports System.IO

Public Class frmAppConfig
    Dim auto_listen_val As Object
    Private Sub frmAppConfig_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If File.Exists(My.Application.Info.DirectoryPath.ToString & "\server.xml") = False Then client_write_configuration()
        client_read_configuration()
        txtHost.Text = listen_host
        txtPort.Text = Convert.ToString(listen_port)
        txtMaxConnections.Text = max_connection
        If Boolean.Parse(auto_start) = True Then
            cbAutoListen.Checked = True
        Else
            cbAutoListen.Checked = False
        End If
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        If File.Exists(My.Application.Info.DirectoryPath.ToString & "\server.xml") = False Then client_write_configuration()

        If cbAutoListen.Checked = True Then
            auto_listen_val = "1"
        Else
            auto_listen_val = "0"
        End If
        client_update_configuration(New Object(0) {}, New Object() {txtHost.Text, txtPort.Text, auto_listen_val, txtMaxConnections.Text}, New Object(0) {})
        client_read_configuration()
        txtHost.Text = listen_host
        txtPort.Text = Convert.ToString(listen_port)
        txtMaxConnections.Text = max_connection
        If Boolean.Parse(auto_start) = True Then
            cbAutoListen.Checked = True
        Else
            cbAutoListen.Checked = False
        End If
        MessageBox.Show("Configuration has been Saved")
    End Sub
End Class